#ifndef _LCD1602_H_
#define _LCD1602_H_

// LCD1602 I2C地址（通常为0x27或0x3F，具体取决于模块）
#define LCD1602_ADDRESS 0x27

// LCD命令定义
#define LCD_CLEAR 0x01
#define LCD_HOME 0x02
#define LCD_ENTRY_MODE 0x04
#define LCD_DISPLAY_CONTROL 0x08
#define LCD_CURSOR_SHIFT 0x10
#define LCD_FUNCTION_SET 0x20
#define LCD_SET_CGRAM 0x40
#define LCD_SET_DDRAM 0x80

// 显示控制选项
#define LCD_DISPLAY_ON 0x04
#define LCD_DISPLAY_OFF 0x00
#define LCD_CURSOR_ON 0x02
#define LCD_CURSOR_OFF 0x00
#define LCD_BLINK_ON 0x01
#define LCD_BLINK_OFF 0x00

// 输入模式选项
#define LCD_ENTRY_RIGHT 0x00
#define LCD_ENTRY_LEFT 0x02
#define LCD_ENTRY_SHIFT_INCREMENT 0x01
#define LCD_ENTRY_SHIFT_DECREMENT 0x00

// 功能设置选项
#define LCD_4BIT_MODE 0x00
#define LCD_2LINE 0x08
#define LCD_5x8_DOTS 0x00

// 控制引脚定义（根据I2C模块的接线）
#define LCD_RS 0x01        // 寄存器选择
#define LCD_RW 0x02        // 读写
#define LCD_EN 0x04        // 使能
#define LCD_BACKLIGHT 0x08 // 背光

void LCD1602_Init();
void LCD1602_WriteCommand(unsigned char Command);
void LCD1602_WriteData(unsigned char Data);
void LCD1602_ReadFlag(unsigned char *Flag);
void LCD1602_ReadData(unsigned char *Data);
void LCD1602_SetCursor(unsigned char X, unsigned char Y);
void LCD1602_PrintString(unsigned char X, unsigned char Y, unsigned char *String);
void LCD1602_PrintNum(unsigned char X, unsigned char Y, unsigned int Number, unsigned char Length);
void LCD1602_PrintSignedNum(unsigned char X, unsigned char Y, int Number, unsigned char Length);
void LCD1602_PrintHexNum(unsigned char X, unsigned char Y, unsigned int Number, unsigned char Length);
void LCD1602_PrintBinNum(unsigned char X, unsigned char Y, unsigned int Number, unsigned char Length);
#endif